package cn.xiangyuanpin.web;

import cn.xiangyuanpin.pojo.Book;
import cn.xiangyuanpin.pojo.Page;
import cn.xiangyuanpin.service.BookService;
import cn.xiangyuanpin.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ClientBookServlet extends BaseServlet{
    private BookService bookService=new BookServiceImpl();

    protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        int pageNo=1;
        int pageSize= Page.PAGE_SIZE;
        try {
            pageNo=Integer.parseInt(req.getParameter("pageNo"));
        } catch (Exception e) {
//            e.printStackTrace();
        }
        try {
            pageSize=Integer.parseInt(req.getParameter("pageSize"));
        } catch (Exception e) {
//            e.printStackTrace();
        }

        Page<Book> page=bookService.page(pageNo,pageSize);

        req.setAttribute("page",page);
        req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp);

    }
}
